package collection;

import object.Point;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo {
    public static void main(String[] args) {
       Collection c=new ArrayList();
       c.add(new Point(1,2));
       c.add(new Point(3,4));
       c.add(new Point(5,6));
       c.add(new Point(7,8));
       c.add(new Point(9,0));
       c.add(new Point(1,2));
       //重写toString（）
       System.out.println(c);

       Point p=new Point(1,2);
       Point p1=new Point(5,6);

       //重写equals()
       boolean contains=c.contains(p);
       boolean contains1=c.contains(p1);
       System.out.println(contains);
       System.out.println(contains1);


       //从当前集合中删除给定元素
        //若存在重复元素则只删除一次
       c.remove(p);
       c.remove(p1);
       System.out.println(c);
       System.out.println(c);

       //集合中存放的是元素的引用
        Collection cc=new ArrayList();
        Point pp=new Point(1,2);
        cc.add(pp);
        System.out.println("pp:"+pp);
        System.out.println("cc:"+cc);

        pp.setX(10);

        System.out.println("pp:"+pp);
        System.out.println("cc:"+cc);
        /*
        Collection c1=new ArrayList();
        c1.add("111");
        c1.add("222");
        c1.add("333");
        c1.add("444");
        //集合重写了Object的toString（）方法，返回格式如下
        //【元素1.toString，元素2.toString，元素3.toString，元素4，toString】
        System.out.println(c1);
        System.out.println(c1.size());
        if(c1.isEmpty()){
            System.out.println("空集");
        }else{
            System.out.println("里面有人");
        }

        c1.clear();
        System.out.println("集合已清空");
        System.out.println(c1);
        System.out.println("size:"+c1.size());
        System.out.println(c1.isEmpty());

        */


        Collection ci=new ArrayList();
        ci.add("one");
        ci.add("two");
        ci.add("three");
        System.out.println(ci.size());
        if(ci.isEmpty()){
            System.out.println("null");
        }else{
            System.out.println("true");
        }

        ci.clear();
        System.out.println(ci);
    }
}
